package com.ruoyi.jetLinks.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.jetLinks.domain.DevProduct;
import com.ruoyi.jetLinks.service.IDevProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 产品Controller
 * 
 * @author lxx
 * @date 2022-01-27
 */
@Api(tags = "产品")
@RestController
@RequestMapping("/jetLinks/devProduct")
public class DevProductController extends BaseController {
    @Autowired
    private IDevProductService devProductService;

    /**
     * 查询产品列表
     */
    @ApiOperation("查询产品列表")
    @PreAuthorize("@ss.hasPermi('jetLinks:devProduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(DevProduct devProduct) {
        startPage();
        List<DevProduct> list = devProductService.selectDevProductList(devProduct);
        return getDataTable(list);
    }


    /**
     * 导出产品列表
     */
    @ApiOperation("导出产品列表")
    @PreAuthorize("@ss.hasPermi('jetLinks:devProduct:export')")
    @Log(title = "产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DevProduct devProduct)
    {
        List<DevProduct> list = devProductService.selectDevProductList(devProduct);
        ExcelUtil<DevProduct> util = new ExcelUtil<DevProduct>(DevProduct.class);
        util.exportExcel(response, list, "产品数据");
    }
    /**
     * 获取产品详细信息
     */
    @ApiOperation("获取产品详细信息")
    @PreAuthorize("@ss.hasPermi('jetLinks:devProduct:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(devProductService.selectDevProductById(id));
    }

    /**
     * 新增产品
     */
    @ApiOperation("新增产品")
    @PreAuthorize("@ss.hasPermi('jetLinks:devProduct:add')")
    @Log(title = "产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DevProduct devProduct) {
        return toAjax(devProductService.insertDevProduct(devProduct));
    }

    /**
     * 修改产品
     */
    @ApiOperation("修改产品")
    @PreAuthorize("@ss.hasPermi('jetLinks:devProduct:edit')")
    @Log(title = "产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DevProduct devProduct) {
        return toAjax(devProductService.updateDevProduct(devProduct));
    }

    /**
     * 删除产品
     */
    @ApiOperation("删除产品")
    @PreAuthorize("@ss.hasPermi('jetLinks:devProduct:remove')")
    @Log(title = "产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(devProductService.deleteDevProductByIds(ids));
    }


}
